package com.whsr.readservice.schedule;

import com.whsr.readservice.service.DownBookMaintainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContext;

@PropertySource("classpath:cron.properties")
@Component
public class DownBookSchedule {

    @Autowired
    private DownBookMaintainService downBookMaintainService;

    @Autowired
    private ServletContext servletContext;

    @Scheduled(cron = "${jobs.downBookSchedule}")
    public void downBookSchedule() {
        Object start = servletContext.getAttribute("start");
        if(start == null){
            servletContext.setAttribute("start", 1);
            downBookMaintainService.downBookJob(0);
            servletContext.removeAttribute("start");
        }
    }


}
